﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Client;
using Dropit.BlogPageProvider.Blog;

namespace Dropit.BlogPageProvider.Blogger
{
	public class Blog : IBlog
	{
		private static string BlogFeedUrl = "http://www.blogger.com/feeds/default/blogs";

		public static List<Blog> List(Service service)
		{
			return Utility.GetFeedEntries(service,Blog.BlogFeedUrl).Select<AtomEntry, Blog>(blog => new Blog()
								{
									BloggerId = new BloggerId()
									{
										BlogId = blog.Id.Uri.ToString()
									},
									Name = blog.Title.Text,
									Summery = blog.Summary.Text,
									Created = blog.Published
								})
								.ToList<Blog>();
		}

		public static Blog Load(Service service, BloggerId id)
		{
			return List(service).First<Blog>(blog => blog.BloggerId.BlogId == id.BlogId);
		}

		public string Id
		{
			get { return BloggerId.ToString(); }
		}

		public BloggerId BloggerId
		{
			get;
			set;
		}

		public string Name
		{
			get;
			set;
		}

		public string Summery
		{
			get;
			set;
		}

		public DateTime Created
		{
			get;
			set;
		}
	}
}
